package vip.xiaonuo.smzq.modular.kcl.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.kcl.entity.Kcp;
import vip.xiaonuo.smzq.modular.kcl.mapper.KcpMapper;
import vip.xiaonuo.smzq.modular.kcl.service.IKcpService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 矿产品 服务实现类
 *
 * @author eomer
 * @since 2024-02-22
 */
@Service
public class KcpServiceImpl extends ServiceImpl<KcpMapper, Kcp> implements IKcpService {

    @Resource
    private KcpMapper kcpMapper;

    @Override
    public Page<Kcp> page(Kcp kcp) {
        QueryWrapper<Kcp> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    /**
     * 矿产品详情查询
     *
     * @Param kqbm 矿区编码
     * @Param djflbm 登记分类编码
     * @Param nd 年度
     */
    @Override
    public List<Kcp> getKcpList(String kqbh, Integer djflbh, Integer nd) {
        List<Kcp> list= new ArrayList<>();
        try {
            QueryWrapper<Kcp> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("kqbh", kqbh).eq("djflbh", djflbh).eq("nd", nd);
            list= kcpMapper.selectList(queryWrapper);
        }catch (Exception e){
            e.printStackTrace();
        }
        return list;
    }

    @Override
    public int addList(List<Kcp> kcpList,String kqbm, Integer djflbm, Integer nd) {
        int count=0;
        for (Kcp kcp :kcpList) {
            kcp.setDjflbh(djflbm);
            kcp.setKqbh(kqbm);
            kcp.setNd(nd);
            if (kcp.getPkid()==null){
                count=count+kcpMapper.insert(kcp);
            }else {
                count=count+kcpMapper.updateById(kcp);
            }

        }
        return count;
    }

    @Override
    public    List<Map> selectAll(String sql) {


        return kcpMapper.selectAll(sql);
    }

    @Override
    public List<String> selectColumnNames(String tableName) {
        return kcpMapper.selectColumnNames(tableName);
    }

    @Override
    public List<Kcp> selectList(QueryWrapper<Kcp> queryWrapperKcp) {
        return kcpMapper.selectList(queryWrapperKcp);
    }
}
